package service

import (
	"go-file-perception-model/internal/model"
	"go-file-perception-model/internal/repository"
	"go-file-perception-model/pkg/vector"
)

// SearchService 搜索服务协调器
type SearchService struct {
	semanticSearchService *SemanticSearchService
	regexSearchService    *RegexSearchService
}

// NewSearchService 创建搜索服务实例
func NewSearchService(vectorDB vector.VectorDB, embeddingModel EmbeddingModel, fileCollector *FileCollector, fileMonitorRepo repository.FileMonitorRepository) *SearchService {
	// 创建高亮处理器（仅用于正则搜索）
	highlighter := NewSearchHighlighter()
	
	// 创建各个专门的搜索服务
	semanticSearchService := NewSemanticSearchService(vectorDB, embeddingModel, fileMonitorRepo)
	regexSearchService := NewRegexSearchService(vectorDB, fileCollector, highlighter)
	
	return &SearchService{
		semanticSearchService: semanticSearchService,
		regexSearchService:    regexSearchService,
	}
}

// SemanticSearch 语义搜索
func (s *SearchService) SemanticSearch(req model.SemanticSearchRequest) ([]*model.SearchResult, error) {
	return s.semanticSearchService.Search(req)
}

// RegexSearch 正则表达式搜索
func (s *SearchService) RegexSearch(req model.RegexSearchRequest) ([]*model.SearchResult, error) {
	return s.regexSearchService.Search(req)
}
